<?php
require_once 'ActionFramework/inputs.php';

class TupleInputTestCase extends PHPUnit_Framework_TestCase
{
    public function testVanilla()
    {
    	$input = new ListInput('DUMMY_NAME', 'dummy name', 
    				new TupleInput(null, null, array(
    					new EmailInput(),
    					new TextInput()
    			 	))
    			 );
    			 
    	
    	$result = $input->validate('[["you@me.org", "aha"], ["you@me.org", "bite"]]');
    	$this->assertTrue($result['valid']);
    	
    	// Invalid input
    	$result = $input->validate('efwef]');
    	$this->assertFalse($result['valid']);
    	
    	// Empty input
    	$result = $input->validate('[]');
    	$this->assertTrue($result['valid']);
    	
    	// Single input
    	$result = $input->validate('[["you@me.org", "aha"]]');
    	$this->assertTrue($result['valid']);
    	
    	// Invalid subinput
    	$result = $input->validate('[["you@me.org", "aha"], ["you-at-me.org", "bite"]]');
    	$this->assertFalse($result['valid']);
    	
    }
    public function testNonZero()
    {
    	$input = new ListInput('DUMMY_NAME', 'dummy name', 
    				new TupleInput(null, null, array(
    					new EmailInput(),
    					new TextInput()
    			 	)),
    			 	1
    			 );
    			 
    	
    	$result = $input->validate('[["you@me.org", "aha"], ["you@me.org", "bite"]]');
    	$this->assertTrue($result['valid']);
    	
    	// Invalid input
    	$result = $input->validate('efwef]');
    	$this->assertFalse($result['valid']);
    	
    	// Empty input
    	$result = $input->validate('[]');
    	$this->assertFalse($result['valid']);
    	
    	// Single input
    	$result = $input->validate('[["you@me.org", "aha"]]');
    	$this->assertTrue($result['valid']);
    	
    	// Invalid subinput
    	$result = $input->validate('[["you@me.org", "aha"], ["you-at-me.org", "bite"]]');
    	$this->assertFalse($result['valid']);
    	
    }
    
    public function testMinLength()
    {
    	$input = new ListInput('DUMMY_NAME', 'dummy name', 
    				new TupleInput(null, null, array(
    					new EmailInput(),
    					new TextInput()
    			 	)),
    			 	2
    			 );
    			 
    	
    	$result = $input->validate('[["you@me.org", "aha"], ["you@me.org", "bite"]]');
    	$this->assertTrue($result['valid']);
    	
    	// Invalid input
    	$result = $input->validate('efwef]');
    	$this->assertFalse($result['valid']);
    	
    	// Empty input
    	$result = $input->validate('[]');
    	$this->assertFalse($result['valid']);
    	
    	// Single input
    	$result = $input->validate('[["you@me.org", "aha"]]');
    	$this->assertFalse($result['valid']);
    	
    	// Invalid subinput
    	$result = $input->validate('[["you@me.org", "aha"], ["you-at-me.org", "bite"]]');
    	$this->assertFalse($result['valid']);
    	
    }

    public function testMaxLength()
    {
    	$input = new ListInput('DUMMY_NAME', 'dummy name', 
    				new TupleInput(null, null, array(
    					new EmailInput(),
    					new TextInput()
    			 	)),
    			 	null, 1
    			 );
    			 
    	
    	$result = $input->validate('[["you@me.org", "aha"], ["you@me.org", "bite"]]');
    	$this->assertFalse($result['valid']);
    	
    	// Invalid input
    	$result = $input->validate('efwef]');
    	$this->assertFalse($result['valid']);
    	
    	// Empty input
    	$result = $input->validate('[]');
    	$this->assertTrue($result['valid']);
    	
    	// Single input
    	$result = $input->validate('[["you@me.org", "aha"]]');
    	$this->assertTrue($result['valid']);
    	
    	// Invalid subinput
    	$result = $input->validate('[["you@me.org", "aha"], ["you-at-me.org", "bite"]]');
    	$this->assertFalse($result['valid']);
    	
    }
    
    public function testCombined()
    {
    	$input = new ListInput('DUMMY_NAME', 'dummy name', 
    				new TupleInput(null, null, array(
    					new EmailInput(),
    					new TextInput()
    			 	)),
    			 	1, 1
    			 );
    			 
    	
    	$result = $input->validate('[["you@me.org", "aha"], ["you@me.org", "bite"]]');
    	$this->assertFalse($result['valid']);
    	
    	// Invalid input
    	$result = $input->validate('efwef]');
    	$this->assertFalse($result['valid']);
    	
    	// Empty input
    	$result = $input->validate('[]');
    	$this->assertFalse($result['valid']);
    	
    	// Single input
    	$result = $input->validate('[["you@me.org", "aha"]]');
    	$this->assertTrue($result['valid']);
    	
    	// Invalid subinput
    	$result = $input->validate('[["you@me.org", "aha"], ["you-at-me.org", "bite"]]');
    	$this->assertFalse($result['valid']);
    	
    }
}